package pull
{
/**
 * @author daichangxin
 */
public class UserInfoSubject implements IUserInfoSubject
{
	private var _observerList:Array = [];
	
	private var _userName:String;
	private var _level:uint;
	private var _golden:uint;
	
	public function setData(data:Object):void
	{
		_userName = data.userName;
		_level = data.level;
		_golden = data.golden;
		
		//发送通知
		notifyObservers();
	}
	
	public function registerObserver(o : IUserInfoObserver) : void
	{
		if (_observerList.indexOf(o) > -1) return;
		
		_observerList.push(o);
	}

	public function removeObserver(o : IUserInfoObserver) : void
	{
		var index:int = _observerList.indexOf(o);
		if (index > 0)
		{
			_observerList.splice(index, 1);
		}
	}

	public function notifyObservers() : void
	{
		for each (var observer : IUserInfoObserver in _observerList) 
		{
			observer.update();
		}
	}

	public function get userName() : String
	{
		return _userName;
	}

	public function get level() : uint
	{
		return _level;
	}

	public function get golden() : uint
	{
		return _golden;
	}
}
}
